from flask import g
from flask import url_for, jsonify
from flask_script import Manager
from flask_migrate import  Migrate,MigrateCommand


from info import creat_app,db,models



# 初始化配置
from info.models import User
from info.response_code import RET

app = creat_app('development')
manage=Manager(app)
migrate=Migrate(app,db)
manage.add_command('db',MigrateCommand)
print(app.url_map)

@manage.option('-n','--name',dest='name')
@manage.option('-p','--password',dest='password')
def createsuperuser(name,password):

    if not all([name,password]):
        print('参数错误，格式：python manage.py createsuperuser -n admin -p 12345678')

    user=User()
    user.nick_name=name
    user.mobile=name
    user.password=password
    user.is_admin=True
    try:
        db.session.add(user)
        db.session.commit()
        print('创建成功')
    except Exception as e:
        print(e)
        db.session.rollback()








if __name__== "__main__":
    manage.run()